/*

This encapsulates a "spherical" camera. That is, the camera is a point on a sphere looking at
some fixed point (the focus). Please refer to a Calculus book for details on spherical
coordinates if you wish to understand the implementation better.

The nice part about this class is that it includes a camera movement mechanism built in by
holding in the right mouse button. Simply hook the mouse event handlers up.

*/

#pragma once

#include <Windows.h>
#include "DirectXMath.h"

class Camera 
{
	// Fields
	float maxPhi, maxRho, maxTheta;
	float minPhi, minRho, minTheta;
	bool moving;
	float phi, rho, theta;
	int prevClickX, prevClickY;
	float radsPerX, radsPerY;
	int refClickX, refClickY;
	float rhosPerDelta;
	HWND windowHandle;

public:
	// Constructor/destructor
	Camera(HWND windowHandle);

	// Getters
	DirectX::XMMATRIX ViewMatrix() const;

	// Setters
	void SetPhi(float phi) { this->phi = phi; }
	void SetRadsPerX(float radsPerX) { this->radsPerX = radsPerX; }
	void SetRadsPerY(float radsPerY) { this->radsPerY = radsPerY; }
	void SetRho(float rho) { this->rho = rho; }
	void SetRhoLimits(float min, float max) { this->minRho = min; this->maxRho = max; }
	void SetRhosPerDelta(float rhosPerDelta) { this->rhosPerDelta = rhosPerDelta; }
	void SetTheta(float theta) { this->theta = theta; }

	// Event handlers
	void OnMouseMove(int x, int y);
	void OnMouseWheel(int x, int y, float delta);
	void OnRightMouseDown(int x, int y);
	void OnRightMouseUp(int x, int y);
};